package com.epower.dao.epowerbook.impl;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.ali.luna.commons.dao.BaseDAOImpl;
import com.epower.dao.epowerbook.EpowerBookDAO;
import com.epower.dataobject.EpowerBookDO;
import java.util.List;

/***
 * DAO实现层
 * 
 * @author QuickDev
 * 
 */
@Scope("singleton")
@Component("epowerBookDAO")
public class EpowerBookDAOImpl extends BaseDAOImpl implements EpowerBookDAO {
	/***
	 * 查询单个对象
	 */
	@Override
	public EpowerBookDO getEpowerBookByOption(EpowerBookDO epowerBook) {
		return (EpowerBookDO) getSqlMapClientTemplate().queryForObject("EpowerBookDAOImpl.GET-EPOWERBOOK-BY-OPTION", epowerBook);
	}

	/***
	 * 查询对象列表
	 */
	@SuppressWarnings("unchecked")
    @Override
	public List<EpowerBookDO> getEpowerBookListByOption(EpowerBookDO epowerBook) {
		return (List<EpowerBookDO>) getSqlMapClientTemplate().queryForList("EpowerBookDAOImpl.GET-EPOWERBOOKList-BY-OPTION", epowerBook);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<EpowerBookDO> getEpowerBookIdsByOption(EpowerBookDO epowerBook) {
		return getSqlMapClientTemplate().queryForList("EpowerBookDAOImpl.getEpowerBookIdsByOption", epowerBook);

	}

	/***
	 * 根据id查询对象
	 */
	@Override
	public EpowerBookDO getEpowerBookById(Integer id) {
		return (EpowerBookDO) getSqlMapClientTemplate().queryForObject("EpowerBookDAOImpl.GET-EPOWERBOOK-BY-ID", id);
	}

	/***
	 * 删除操作
	 */
	@Override
	public boolean deleteEpowerBookById(Integer id) {
		int num = getSqlMapClientTemplate().update("EpowerBookDAOImpl.DELETE-EPOWERBOOK-BY-ID", id);
		return num == 0 ? false : true;
	}

	/***
	 * 查询数量
	 */
	@Override
	public Integer getEpowerBookCountByOption(EpowerBookDO epowerBook) {
		return (Integer) getSqlMapClientTemplate().queryForObject("EpowerBookDAOImpl.GET-EPOWERBOOK-COUNT-BY-OPTION", epowerBook);
	}

	/***
	 * 更新操作
	 */
	@Override
	public boolean updateEpowerBookByOption(EpowerBookDO epowerBook) {
		int num = getSqlMapClientTemplate().update("EpowerBookDAOImpl.UPDATE-EPOWERBOOK-BY-OPTION", epowerBook);
		return num == 0 ? false : true;
	}

	/***
	 * 添加操作
	 * 
	 * @param
	 * @return
	 */
	@Override
	public Integer addEpowerBook(EpowerBookDO epowerBook) {
		return (Integer) getSqlMapClientTemplate().insert("EpowerBookDAOImpl.ADD-EPOWERBOOK", epowerBook);
	}

	@Override
	public boolean isBook(Integer id) {

		return (Integer) getSqlMapClientTemplate().insert("EpowerBookDAOImpl.isBook", id) > 0;
	}

    @SuppressWarnings("unchecked")
    @Override
    public List<EpowerBookDO> getEpowerBookListByName(EpowerBookDO epowerBook) {
        return getSqlMapClientTemplate().queryForList("EpowerBookDAOImpl.getEpowerBookListByName", epowerBook);
    }

    @Override
    public List<EpowerBookDO> getEpowerBookListByPid(int pid) {
        return getSqlMapClientTemplate().queryForList("EpowerBookDAOImpl.getEpowerBookListByPid", pid);
    }

}